package com.example.de.moraligmbh.application;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

/**
 * 
 * @author meriem falah
 *
 */
public class Form extends Activity implements OnClickListener
{
	
    private static final int FORMULA_KONSTANT = 113;
	private EditText massField;
	private EditText pressionField;
	private EditText numOfSuctionPadField;
	private EditText safetyFactorField;
	private EditText coefficientField;
	private Button executeButton;
	private Button resetButton;
	private TextView computationResult;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_form);
        // instantiate the edittexts
		massField = (EditText) findViewById(R.id.editText1);
		pressionField = (EditText) findViewById(R.id.EditText2);
		numOfSuctionPadField = (EditText) findViewById(R.id.EditText3);
		safetyFactorField = (EditText) findViewById(R.id.EditText4);
		coefficientField = (EditText) findViewById(R.id.EditText5);
		
		computationResult =  (TextView) findViewById(R.id.computationResult);
	
		executeButton = (Button) findViewById(R.id.executeButton);
		
		
		// Adding ActionListener to buttons
		executeButton.setOnClickListener(this);
		
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.form, menu);
        return true;
    }
	@Override
	public void onClick(View v) {
		
		double mass = Double.parseDouble(massField.getText().toString());
		double pression = Double.parseDouble(pressionField.getText().toString());
		int numSuctionPad = Integer.parseInt(numOfSuctionPadField.getText().toString());
		int safety_factor = Integer.parseInt(safetyFactorField.getText().toString());
		//double coefficient = Integer.parseInt(coefficientField.getText().toString());
		
		// Computing from the given variables the diameter, then
		// saving the result in the variable result
		double quotient = (mass * safety_factor) / (pression * numSuctionPad);
		double result = FORMULA_KONSTANT * Math.sqrt(quotient);
		double rounding_result = Math.ceil(result);
		computationResult.setText(rounding_result+"");
		
		
	}
    
}
